<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">

    <link rel="stylesheet" href="../bootstrap-3.3.4/dist/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../Flat-UI-master/dist/css/flat-ui.min.css"/>
    <script src="../Flat-UI-master/dist/js/vendor/jquery.min.js"></script>
    <script src="../bootstrap-3.3.4/dist/js/bootstrap.min.js"></script>
    <script src="../Flat-UI-master/dist/js/flat-ui.min.js"></script>
    <title></title>
    <style>
        .row{
            margin-left: 20px;
            margin-right: 20px;;
        }
        .line-center{
            line-height:50px;
            text-align: center;
        }
        .row input{
            width: 50px;
        }
        .list-group-item:hover{
            background: #27ae60;

        }
        .list-group-item div:first-child:hover{

            cursor: pointer;
        }
        th{
            text-align: right;
            width: 10%;;
            padding: 10px;
        }
        td{
            text-align: left;
            width: 30%;;
            padding: 10px;
        }
        .table th{
            text-align: center;
        }
        .table td{
            text-align: center;
        }
    </style>
    <script>
        function myClick(n){
            location.href = "OrderInfo.html";
        }
        function btnClick(){
            alert("btn");
            return false;
        }
        $(function(){

        })
    </script>
    <script>
        $(function(){
            $('#myTabs a').click(function (e) {

                $(this).tab('show')
            });
        })
    </script>
    <script src="../js/jquery-3.2.1.min.js"></script>
</head>
<body>
<!-- Static navbar -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">这什么东西</span>
            </button>
            <a class="navbar-brand" href="Index.html">图书商城</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="Index.html">首页</a></li>
                <li><a href="Order.html">我的订单</a></li>
                <li><a href="UserInfo.html">个人中心</a></li>
                <li><a href="FriendLink.html">友情链接</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right hidden-sm">
                <li><a href="Login.html">登录</a></li>
                <li><a href="Register.html">注册</a></li>
                <li><a id="out">退出</a></li>
                <li>
                    <a href="Cart.html"><span class="glyphicon glyphicon-shopping-cart">购物车</span></a></li>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</div>
<!--content-->
<div class="container">
    <div class="row thumbnail center col-sm-12">
        <div class="col-sm-12">
            <h1 class="text-center" style="margin-bottom: 30px">个人中心</h1>
        </div>

        <ul class="nav nav-tabs nav-justified" id="myTabs">
            <li id="userHome"><a>个人中心</a></li>
            <li id="editInfo"><a>信息修改</a></li>
            <li id="editPassword"><a>密码修改</a></li>
            <li id="orderManager"><a>订单管理</a></li>
        </ul>

        <!-- Tab panes -->
        <div class="tab-content">
            <!--active-->
            <div role="tabpanel" class="tab-pane">个人中心</div>
            <div role="tabpanel" class="tab-pane" >信息修改</div>
            <div role="tabpanel" class="tab-pane" >密码修改</div>
            <div role="tabpanel" class="tab-pane" >订单管理</div>
        </div>

</div>
    <div>
        <div id="user">
            <table>
                <tr>
                    <th>用户名:</th><td id="username"></td>
                </tr>
                <tr>
                    <th>email:</th><td id="email"></td>
                </tr>
                <tr>
                    <th>性别:</th><td id="gender"></td>
                </tr>
                <tr>
                    <th>收货地址：</th><td id="address"></td>
                </tr>
                <tr>
                    <th>收货电话：</th><td id="phone"></td>
                </tr>
            </table>
        </div>
        <div id="change">
            邮箱:<input type='text' placeholder='请输入修改后的邮箱' id="changeemail" class=' form-control text-center email' style='width: 20%'>
            电话:<input type='text' placeholder='请输入修改后的电话' id="changeph" class=' form-control text-center email' style='width: 20%'>
            地址:<input type='text' placeholder='请输入修改后的地址' id="changeaddress" class=' form-control text-center email' style='width: 20%'>
            <input type="button" id="tochange" value="提交">
            <span id="changespan"></span>
        </div>
        <div id="passchange">
            旧密码:<input type='text' placeholder='请输入旧密码' id="password" class=' form-control text-center email' style='width: 20%'>
            新密码:<input type='text' placeholder='请输入新密码' id="newpassword" class=' form-control text-center email' style='width: 20%'>
            确认新密码:<input type='text' placeholder='请再次输入新密码' id="newrepwd" class=' form-control text-center email' style='width: 20%'>
            <input type="button" value="提交" id="changepass">
            <span id="passchangespan"></span>
        </div>
        <div id="order">

        </div>
    </div>
    </div>

<!--footer-->
<div class="navbar navbar-default navbar-static-bottom">
    版权声明区
</div>
<script>
    var username;
    var email;
    var address;
    var gender;
    var phone;
    window.onload=function () {
        $("#user").show();
        $("#change").hide();
        $("#passchange").hide();
        $("#order").hide();
        $.ajax({
            url:"/user",
            type:"get",
            success:function (re) {
                if (re.code == 1003) {
                    console.log(re.msg)
                    location.href="/Home/Login.html"
                }else if (re.code == 1001) {
                    console.log(re.msg)
                }else if (re.code == 1000) {
                    $("#username").html(re.data.username);
                    $("#email").html(re.data.email);
                    $("#address").html(re.data.address);
                    $("#gender").html(re.data.gender);
                    $("#phone").html(re.data.phone);
                    username = re.data.username;
                    email = re.data.email;
                    address =re.data.address;
                    gender = re.data.gender;
                    phone = re.data.gender;
                }
            }
        })
    }
    $("#userHome").click(function () {
        $("#user").hide();
        $("#change").hide();
        $("#passchange").hide();
        $("#order").hide();

        $("#user").show();

        $("#userHome").removeClass("active");
        $("#editInfo").removeClass("active");
        $("#editPassword").removeClass("active");
        $("#orderManager").removeClass("active");
        $("#userHome").addClass("active");
    })
    $("#editInfo").click(function () {
        $("#user").hide();
        $("#change").hide();
        $("#passchange").hide();
        $("#order").hide();

        $("#change").show();

        $("#userHome").removeClass("active");
        $("#editInfo").removeClass("active");
        $("#editPassword").removeClass("active");
        $("#orderManager").removeClass("active");
        $("#editInfo").addClass("active");
    })
    $("#editPassword").click(function () {
        $("#user").hide();
        $("#change").hide();
        $("#passchange").hide();
        $("#order").hide();

        $("#passchange").show();

        $("#userHome").removeClass("active");
        $("#editInfo").removeClass("active");
        $("#editPassword").removeClass("active");
        $("#orderManager").removeClass("active");
        $("#editPassword").addClass("active");
    })
    $("#orderManager").click(function () {
        $("#user").hide();
        $("#change").hide();
        $("#passchange").hide();
        $("#order").hide();

        $("#order").show();

        $("#userHome").removeClass("active");
        $("#editInfo").removeClass("active");
        $("#editPassword").removeClass("active");
        $("#orderManager").removeClass("active");
        $("#orderManager").addClass("active");
        location.href="/Home/Order.html"
    })
    $("#tochange").click(function () {
        var email1=$("#changeemail").val();
        if (email1 == null) {
            email1 = email;
        }
        var phone1 = $("#changeph").val();
        if (phone1 == null) {
            phone1 = phone;
        }
        var address1=$("#changeaddress").val();
        if (address1 == null) {
            address1 = address;
        }
         // id="changeemail"
         //    id="changeph"
         //     id="changeaddress
        $.ajax({
            url:"/changuser",
            type:"get",
            data:{
                email:email1,
                phone:phone1,
                address:address1
            },
            success:function (re) {
                if (re.code == 1003) {
                    location.href="/Home/Login.html"
                }else if(re.code==1001){
                    console.log(re.msg)
                    $("#changespan").html(re.msg)
                }else if (re.code == 1000) {
                    console.log(re.msg)
                    $("#changespan").html(re.msg)
                }
            }
        })
    })
    $("#changepass").click(function () {
        var password = $("#password").val();
        var newpassword = $("#newpassword").val();
        var newrepwd = $("#newrepwd").val();
        if (newpassword != null) {
            $.ajax({
                url:"/changepass",
                type:"get",
                data:{
                    password:password,
                    newpassword:newpassword,
                    newrepwd:newrepwd
                },
                success:function (re) {
                    $("#passchangespan").html(re.msg)
                }
            })
        }else {
            $("#passchangespan").html("新密码不能为空")
        }

    })
    $("#out").click(function () {
        $.ajax({
            url:"/out",
            type:"get",
            success:function (re) {
                if (re.code == 1000) {
                    location.href="/Home/Login.html"
                }
            }
        })
    })
</script>
</body>
</html>